/*
 * @Author: your name
 * @Date: 2021-12-30 09:39:56
 * @LastEditTime: 2022-01-19 11:05:27
 * @LastEditors: piaopiao.huang
 * @Description: In User Settings Edit
 */

import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store'
// import { getToken } from '@/utils/auth'
//路由重定向
const REDIRECT =  process.env.VUE_APP_ROUTER_REDIRECT;

Vue.use(Router)
// 路由配置
export const constantRoutes = [
  {
    path: '/',
    redirect: REDIRECT || 'allocation'
  },
  // 盘点
  {
    path: '/allocation',
    name: 'allocation',
    component: () => import('@/views/allocation/index.vue')
  },
  {
    path: '/allocation/add',
    name: 'allocationAdd',
    component: () => import('@/views/allocation/add.vue')
  },
  {
    path: '/allocation/addIndex',
    name: 'allocationAddDetil',
    component: () => import('@/views/allocationDetail/addIndex.vue')
  },
  // 盘点详情
  {
    path: '/allocationDetail',
    name: 'allocationDetail',
    component: () => import('@/views/allocationDetail/index.vue')
  },
  {
    path: '/allocationDetail/form',
    name: 'allocationDetailForm',
    component: () => import('@/views/allocationDetail/add.vue')
  },
  {
    path: '/materialDetail',
    name: 'materialDetail',
    component: () => import('@/views/materialInfo/index.vue')
  },
  {
    path: '/materialSelect',
    name: 'materialSelect',
    component: () => import('@/views/materialSelect/index.vue')
  },
  {
    path: '/batch',
    name: 'batch',
    component: () => import('@/views/batch/index.vue')
  },
  {
    path: '/addRefType',
    name: 'addRefType',
    component: () => import('@/views/allocation/addRefType.vue')
  },
  {
    path: '/materialDetailSelect',
    name: 'materialDetailSelect',
    component: () => import('@/views/materialDetailSelect/index.vue')
  },
  // // 生产报工
  // {
  //   path: '/productionReport',
  //   name: 'productionReport',
  //   component: () => import('@/views/productionReport/index.vue')
  // },
  // // 报工详情
  // {
  //   path: '/reportDetail',
  //   name: 'reportDetail',
  //   component: () => import('@/views/reportDetail/index.vue')
  // },
  // // 附件列表
  // {
  //   path: '/appendix',
  //   component: () => import('@/views/appendix/index.vue'),
  //   name: 'appendix'
  // },
  // // 视频预览
  // {
  //   path: '/video',
  //   component: () => import('@/views/appendix/components/video.vue'),
  //   name: 'videoFile'
  // },
  // {
  //   path: '/temp',
  //   name: 'temp',
  //   component: () => import('@/views/workOrderList/temp.vue')
  // },
  /** 发那特 */
  {
    path:"/proMaterialReq",  //简单生产领料单
    name:"ProductionMaterialRequest",
    component:() => import("@/pages/productionMaterialRequest/index.vue")
  },
  {
    path:"/proMaterialRet",  //简单生产退料单
    name:"ProductionMaterialReturn",
    component:() => import("@/pages/productionMaterialReturn/index.vue")
  },
  {
    path:"/proEntInve",  //简单生产入库(扫码小程序)
    name:"ProductionEnterInventory",
    component:() => import("@/pages/productionEnterInventory/index.vue")
  },
  {
    path:"/proRetInve",  //简单生产退库
    name:"ProductionReturnInventory",
    component:() => import("@/pages/productionReturnInventory/index.vue")
  },
  {
    path:"/proMaterialRetSto",  //生产退库单
    name:"ProductionMaterialReturnToStock",
    component:() => import("@/pages/productionMaterialReturnToStock/index.vue")
  },
  {
    path:"/batNumAdjForm",  //批号调整单扫码小程序
    name:"BatchNumberAdjustmentForm",
    component:() => import("@/pages/batchNumberAdjustmentForm/index.vue")
  },
  /** 寸金 */
  {
    path:"/purchaseInventory",  //采购入库
    name:"PurchaseInventory",
    component:() => import("@/pages/purchaseInventory/index.vue")
  },
  {
    path:"/purchaseInventory/add",
    name:"PurchaseInventoryAdd",
    component:() => import("@/pages/purchaseInventory/add.vue")
  },
  {
    path:"/purchaseInventory/purchaseOrder",
    name:"PurchaseOrder",
    component:() => import("@/pages/purchaseInventory/purchaseOrderSelect.vue")
  },
  {
    path:"/purchaseInventory/detail",
    name:"PurchaseInventoryDetail",
    component:() => import("@/pages/purchaseInventory/detail.vue")
  },
  {
    path:"/productInventory",  //生产入库
    name:"ProductInventory",
    component:() => import("@/pages/productInventory/index.vue")
  },
  {
    path:"/productInventory/add",
    name:"ProductInventoryAdd",
    component:() => import("@/pages/productInventory/add.vue")
  },
  {
    path:"/productInventory/productOrder",
    name:"ProductOrder",
    component:() => import("@/pages/productInventory/productOrderSelect.vue")
  },
  {
    path:"/productInventory/productOrder2",
    name:"ProductOrder2",
    component:() => import("@/pages/productInventory/productOrderSelect2.vue")
  },
  {
    path:"/productInventory/detail",
    name:"ProductInventoryDetail",
    component:() => import("@/pages/productInventory/detail.vue")
  },
  {
    path:"/outsourcingInventory",  //委外订单入库
    name:"OutsourcingInventory",
    component:() => import("@/pages/outsourcingInventory/index.vue")
  },
  {
    path:"/outsourcingInventory/add",
    name:"OutsourcingInventoryAdd",
    component:() => import("@/pages/outsourcingInventory/add.vue")
  },
  {
    path:"/outsourcingInventory/outsourcingOrder",
    name:"OutsourcingOrder",
    component:() => import("@/pages/outsourcingInventory/outsourcingOrderSelect.vue")
  },
  {
    path:"/outsourcingInventory/detail",
    name:"OutsourcingInventoryDetail",
    component:() => import("@/pages/outsourcingInventory/detail.vue")
  },
  {
    path:"/deliveryStorage",  //销售出库
    name:"DeliveryStorage",
    component:() => import("@/pages/deliveryStorage/index.vue")
  }
]

const createRouter = () =>
  new Router({
  scrollBehavior: () => ({ y: 0 }), 
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

// 路由守卫 判断是否登录了
router.beforeEach((to, from, next) => {
  store.commit('routerQuery/SET_ROUTEQUERY',{to:to,from:from})
  // if (to.path === '/login') {
  //   next()
  // } else {
  //   const token = getToken()
  //   if (!token) {
  //     next('/login')
  //   } else {
  //     next()
  //   }
  // }
  next()
})

export default router
